// The NSpring Framework for .NET
// Copyright (c) 2003, Jeffrey Varszegi
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without modification, 
// are permitted provided that the following conditions are met:
// 
// - Redistributions of source code must retain the above copyright notice, this 
// list of conditions and the following disclaimer.
// 
// - Redistributions in binary form must reproduce the above copyright notice, this 
// list of conditions and the following disclaimer in the documentation and/or other 
// materials provided with the distribution.
// 
// - Neither the name of the NSpring project nor the names of its contributors may 
// be used to endorse or promote products derived from this software without 
// specific prior written permission from the copyright owner.
// 
// - No product derived from this software may be called "NSpring", nor may 
// "NSpring" appear in the name of such a product, without specific prior written 
// permission from the copyright owner.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
// OF THE POSSIBILITY OF SUCH DAMAGE. 

namespace NSpring.Logging {

using System;

using NSpring.Logging.EventFormatters;

/// <summary>
/// <para>
/// A message or record to be written to a log; the record of an application event to be written 
/// to one or more output devices represented by Logger instances.  Event instances are usually 
/// not created directly by application code, but rather by loggers that receive calls to their 
/// Log methods.
/// </para>
/// </summary>
public sealed class Event {
    private static EventFormatter eventFormatter        = new XMLEventFormatter();
    
    private Context context;
    private string id;
    private Level level;
    private DateTime timestamp;
    private string message;
    private object data;
    private string category;
    private string code;
    
    /// <summary>
    /// The thread context of the event (optional)
    /// </summary>
    public Context Context {
        get {
            return context;
        }
        set {
            if (context == null) {
                context = value;
            }
        }
    }
    
    /// <summary>
    /// The ID, usually a GUID, of the event (optional)
    /// </summary>
    public string ID {
        get {
            return id;
        }
        set {
            if (id == null) {
                id = value;
            }
        }
    }
    
    /// <summary>
    /// The Level of the record
    /// </summary>
    public Level Level {
        get {
            return level;
        }
        set {
            if (level == null) {
                level = value;
            }
        }
    }
	
    /// <summary>
    /// The timestamp when the record was created
    /// </summary>
    public DateTime Timestamp {
        get {
            return timestamp;
        }
    }
	
	/// <summary>
	/// The string message associated with this record (optional)
	/// </summary>
    public string Message {
        get {
            return message;
        }
        set {
            if (message == null) {
                message = value;
            }
        }
    }
    
    /// <summary>
    /// The data object associated with this record (optional)
    /// </summary>
    public object Data {
        get {
            return data;
        }
        set {
            if (data == null) {
                data = value;
            }
        }
    }
    
    /// <summary>
    /// The category of the associated event (optional)
    /// </summary>
    public string Category {
        get {
            return category;
        }
        set {
            if (category == null) {
                category = value;
            }
        }
    }
    
    /// <summary>
    /// The code of the associated event; may be used to store the error code
    /// in the event of an exception (optional)
    /// </summary>
    public string Code {
        get {
            return code;
        }
        set {
            if (code == null) {
                code = value;
            }
        }
    }
    
    /// <summary>
    /// Creates an Event
    /// </summary>
    public Event() {
        timestamp = DateTime.Now;
    }

    /// <summary>
    /// Creates an Event
    /// </summary>
    public Event(DateTime _timestamp) {
        timestamp = _timestamp;
    }
    
    /// <summary>
    /// Creates an Event
    /// </summary>
    public Event(Level _level, string _message, object _data, string _category, string _code) {
        timestamp = DateTime.Now;
        level = _level;
        message = _message;
        data = _data;
        category = _category;
        code = _code;

        context = null;
        id = null;
    }
    
    /// <summary>
    /// Creates an Event
    /// </summary>
    public Event(DateTime _timestamp, Level _level, string _message, object _data, string _category, string _code) {
        timestamp = _timestamp;
        level = _level;
        message = _message;
        data = _data;
        category = _category;
        code = _code;

        context = null;
        id = null;
    }
    
    /// <summary>
    /// Creates an Event
    /// </summary>
    public Event(Level _level, string _message, object _data, string _category, string _code, string _id) {
        timestamp = DateTime.Now;
        level = _level;
        message = _message;
        data = _data;
        category = _category;
        code = _code;
        id = _id;

        context = null;
    }
    
    /// <summary>
    /// Creates an Event
    /// </summary>
    public Event(DateTime _timestamp, Level _level, string _message, object _data, string _category, string _code, string _id) {
        timestamp = _timestamp;
        level = _level;
        message = _message;
        data = _data;
        category = _category;
        code = _code;
        id = _id;

        context = null;
    }

    public override string ToString() {
        return eventFormatter.Format(this);
    }
    
}

}
